home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '92 / Hacks ’92 / BlueDot Hack ƒ / BlueDot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-18  |  3.8 KB  |  158 lines  |  [TEXT/KAHL]

  1.  
  2. #include "Interface-Effect.h"
  3.  
  4. //———————————————————————————————————————————————
  5. // Perform the effect
  6.  
  7. #define kDefaultWidth        80
  8. #define kDefaultHeight        60
  9. #define kDefaultLeft        0
  10. #define kDefaultTop            0
  11.  
  12. #define kMinTotalMem        5000
  13. #define kMinContigMem        4000
  14.  
  15. #define kDialogID            1000
  16. #define kOKItem                1
  17. #define kLeftItem            2
  18. #define kTopItem            3
  19. #define kWidthItem            4
  20. #define kHeightItem            5
  21.  
  22. OSErr     DoTheDialog( EffectHandle theData );
  23. void     SetDialogNumber( DialogPtr theDialog, short theItem, long theValue );
  24. long     GetDialogNumber( DialogPtr theDialog, short theItem );
  25.  
  26.  
  27. pascal short main(short selector, EffectHandle theData)
  28. {
  29.     short                result = 0;
  30.     Rect                aRect, bRect, dRect;
  31.     Rect                theBlueRect;
  32.     CGrafPtr            oldPort;
  33.     GDHandle            oldGDevice;
  34.     RGBColor            blueColor, oldColor;
  35.     
  36.     switch (selector) 
  37.     {
  38.         case esExecute:    
  39.             GetGWorld( &oldPort, &oldGDevice );
  40.             aRect = ((GrafPtr)(*theData)->source1)->portRect;
  41.             bRect = ((GrafPtr)(*theData)->source2)->portRect;
  42.             dRect = ((GrafPtr)(*theData)->destination)->portRect;
  43.             
  44.                 // copy all of source 1
  45.             CopyBits((BitMap*)&(*theData)->source1->portPixMap,    
  46.                         (BitMap*)&(*theData)->destination->portPixMap,
  47.                                                         &aRect,&dRect,srcCopy,nil);
  48.  
  49.                 // get the rectangle
  50.             if ( (**theData).specsHandle )
  51.             {
  52.                 theBlueRect = **(Rect**)(**theData).specsHandle;
  53.             }
  54.             else
  55.             {
  56.                 SetRect( &theBlueRect, kDefaultLeft, kDefaultTop, 
  57.                                 kDefaultLeft + kDefaultWidth, kDefaultTop + kDefaultHeight );
  58.             }
  59.             SetGWorld( (*theData)->destination, NULL );
  60.             blueColor.red = blueColor.green = 5000;
  61.             blueColor.blue = 45000L;
  62.             GetForeColor( &oldColor );
  63.             RGBForeColor( &blueColor );
  64.             PaintOval( &theBlueRect );
  65.             RGBForeColor( &oldColor );
  66.             SetGWorld( oldPort, oldGDevice );        // restore port
  67.             break;
  68.         case esSetup:
  69.             result = DoTheDialog( theData );
  70.             break;
  71.     }
  72.     return(result);
  73. }
  74.  
  75.  
  76. OSErr DoTheDialog( EffectHandle theData )
  77. {
  78.     Handle        h = NULL;
  79.     short        itemHit;
  80.     DialogPtr    theDialog;
  81.     long        contigMem, totalMem;
  82.     Rect        r;
  83.     
  84.     InitCursor();        // Premiere leaves it as something dumb
  85.     
  86.     PurgeSpace( &totalMem, &contigMem );
  87.     if ( (totalMem < kMinTotalMem) || (contigMem < kMinContigMem) )
  88.         return( memFullErr );
  89.     
  90.     if ( (**theData).specsHandle )
  91.         r = **(Rect**)(**theData).specsHandle;
  92.     else
  93.     {
  94.         h = NewHandle( sizeof(Rect) );
  95.         if ( !h ) return( memFullErr );
  96.         SetRect( &r, kDefaultLeft, kDefaultTop, 
  97.                         kDefaultLeft+kDefaultWidth, kDefaultTop+kDefaultHeight );
  98.     }
  99.     
  100.     theDialog = GetNewDialog( kDialogID, NULL, (WindowPtr)-1 );
  101.     if ( !theDialog ) return( resNotFound );
  102.     
  103.     SetDialogNumber( theDialog, kLeftItem, r.left );
  104.     SetDialogNumber( theDialog, kTopItem, r.top );
  105.     SetDialogNumber( theDialog, kWidthItem, r.right - r.left );
  106.     SetDialogNumber( theDialog, kHeightItem, r.bottom - r.top );
  107.     SelIText( theDialog, kLeftItem, 0, 999 );
  108.     
  109.     do
  110.     {
  111.         ModalDialog( NULL, &itemHit );
  112.     } while ( itemHit != kOKItem );
  113.     
  114.     r.left = GetDialogNumber( theDialog, kLeftItem );
  115.     r.top = GetDialogNumber( theDialog, kTopItem );
  116.     r.right = r.left + GetDialogNumber( theDialog, kWidthItem );
  117.     r.bottom = r.top + GetDialogNumber( theDialog, kHeightItem );
  118.     
  119.     if ( h )
  120.     {
  121.         (**(Rect**)h) = r;
  122.         (**theData).specsHandle = h;
  123.     }
  124.     else
  125.         **(Rect**)(**theData).specsHandle = r;
  126.     
  127.     DisposeDialog( theDialog );
  128.     return( noErr );
  129. }
  130.  
  131. void SetDialogNumber( DialogPtr theDialog, short theItem, long theValue )
  132. {
  133.     short    itemKind;
  134.     Handle    itemHandle;
  135.     Rect    itemR;
  136.     Str255    aString;
  137.     
  138.     GetDItem( theDialog, theItem, &itemKind, &itemHandle, &itemR );
  139.     NumToString( theValue, aString );
  140.     SetIText( itemHandle, aString );
  141. }
  142.  
  143. long GetDialogNumber( DialogPtr theDialog, short theItem )
  144. {
  145.     short    itemKind;
  146.     Handle    itemHandle;
  147.     Rect    itemR;
  148.     long    result = 0;
  149.     Str255    aString;
  150.     
  151.     GetDItem( theDialog, theItem, &itemKind, &itemHandle, &itemR );
  152.     GetIText( itemHandle, aString );
  153.     StringToNum( aString, &result );
  154.     
  155.     return( result );
  156. }
  157.  
  158.